﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Entities;

namespace WebUI.Binders
{
    public class FilterModelBinder : IModelBinder
    {
        private const string sessionKey = "Filter";

        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            FilterOperations filter = (FilterOperations)controllerContext.HttpContext.Session[sessionKey];

            if (filter == null)
            {
                filter = new FilterOperations();
                controllerContext.HttpContext.Session[sessionKey] = filter;
            }

            return filter;
        }
    }
}